/**
 * @filename:WithdrawServiceImpl 2023-4-24
 * @project Wonder Java前后台分离框架  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.service.impl;

import com.wonder.app.domain.Withdraw;
import com.wonder.app.vo.WithdrawVo;
import com.wonder.app.mapper.WithdrawDao;
import com.wonder.app.service.WithdrawService;
import com.wonder.app.request.WithdrawRequest;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.Date;

/**   
 * @Description:TODO(用户提现服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 * 
 */
@Service
public class WithdrawServiceImpl  extends ServiceImpl<WithdrawDao, Withdraw> implements WithdrawService  {

    /**
     * 验证用户提现信息
     * 
     * @param withdraw
     * @param type
     * @return String
     */
    @Override
    public String validate(Withdraw withdraw,String type){
    
    
       return "";
    }
    
    
    /*
	 * 分页返回，自定义多表分页数据返回
	 */
	@Override 
    public IPage<WithdrawVo> selectWithdrawVoList(WithdrawRequest request, Page<WithdrawVo> page){
	    QueryWrapper<WithdrawVo> queryWrapper = new QueryWrapper<>();
	    
	    if (null != request.getId()) {
	       queryWrapper.eq("a.id", request.getId());
	      }               
             
	    if (null != request.getUid()) {
	       queryWrapper.eq("a.uid", request.getUid());
	      }               
             
	    if (null != request.getStatus()) {
	       queryWrapper.eq("a.status", request.getStatus());
	      }               
             
        if (request.getCreate_time() != null){
        	Date[] create_time=request.getCreate_time();
        	if(create_time.length>0)
        	  queryWrapper.ge("a.create_time", create_time[0]); 
        	if(create_time.length==2)
        	  queryWrapper.le("a.create_time",create_time[1]);      
        	
        }    
             
	    if (null != request.getAgent()) {
	       queryWrapper.eq("a.agent", request.getAgent());
	      }               
             
        if (StringUtils.hasText(request.getUser_real_name())) {
			    queryWrapper.like("b.real_name", request.getUser_real_name()); 
		    } 
             
        if (StringUtils.hasText(request.getUser_phone())) {
			    queryWrapper.like("b.phone", request.getUser_phone()); 
		    } 
             
        
		queryWrapper.orderByDesc("a.id");	
		IPage<WithdrawVo> selectPage = this.baseMapper.getWithdrawVoList(page, queryWrapper);
		return selectPage;
    }
    
    /**
	 * 返回VO单个数据
	 */
	@Override 
	public WithdrawVo getVoById(Long id){
	    QueryWrapper<WithdrawVo> queryWrapper=new QueryWrapper<WithdrawVo>().eq("a.id", id);
		return this.baseMapper.getWithdrawVoList(queryWrapper);
	}
	
    /**
	 * Description:用户提现分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<Withdraw>   //分页记录
	 */
	@Override 
	public IPage<Withdraw> selectList(WithdrawRequest request, Page<Withdraw> page){
	    LambdaQueryWrapper<Withdraw> lambdaQueryWrapper = new LambdaQueryWrapper<>();
	    
	    if (null != request.getId()) {
	       lambdaQueryWrapper.eq(Withdraw::getId, request.getId());
	      }               
             
	    if (null != request.getUid()) {
	       lambdaQueryWrapper.eq(Withdraw::getUid, request.getUid());
	      }               
             
	    if (null != request.getStatus()) {
	       lambdaQueryWrapper.eq(Withdraw::getStatus, request.getStatus());
	      }               
             
        if (request.getCreate_time() != null){
        	Date[] create_time=request.getCreate_time();
        	if(create_time.length>0)
        	  lambdaQueryWrapper.ge(Withdraw::getCreate_time, create_time[0]); 
        	if(create_time.length==2)
        	  lambdaQueryWrapper.le(Withdraw::getCreate_time,create_time[1]);      
        	
        }    
             
	    if (null != request.getAgent()) {
	       lambdaQueryWrapper.eq(Withdraw::getAgent, request.getAgent());
	      }               
             
        if (StringUtils.hasText(request.getUser_real_name())) {
			    lambdaQueryWrapper.like(Withdraw::getUser_real_name, request.getUser_real_name()); 
		    } 
             
        if (StringUtils.hasText(request.getUser_phone())) {
			    lambdaQueryWrapper.like(Withdraw::getUser_phone, request.getUser_phone()); 
		    } 
             
        
		lambdaQueryWrapper.orderByDesc(Withdraw::getId);	
		Page<Withdraw> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
    }
        
	/**
	 * 批准
	 */
	@Override  
	public AjaxResult<Object> approve(Withdraw withdraw){
	   this.baseMapper.updateById(withdraw);
	  return AjaxResult.success();
	}
	
	/**
	 * 取消
	 */
	@Override  
	public AjaxResult<Object> cancel(Withdraw withdraw){
	   this.baseMapper.updateById(withdraw);
	  return AjaxResult.success();
	}
	
	/**
	 * 支付
	 */
	@Override  
	public AjaxResult<Object> Pay(Withdraw withdraw){
	   this.baseMapper.updateById(withdraw);
	  return AjaxResult.success();
	}
	
	/**
	 * 驳回
	 */
	@Override  
	public AjaxResult<Object> reject(Withdraw withdraw){
	   this.baseMapper.updateById(withdraw);
	  return AjaxResult.success();
	}
	
    
	
}